package com.sgb.kjwl.view.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityCentralizedBinding;
import com.sgb.kjwl.di.home.DaggerHomeComponent;
import com.sgb.kjwl.di.home.HomeModule;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.kjwl.viewmodel.home.CentralizedModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.recyclerview.adapter.FragPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * 2020-7-15 20:21:06
 * 集采列表（筛选）
 */
@Deprecated
public class CentralizedActivity extends AppActivity {

    @Inject
    CentralizedModel viewModel;
    private ActivityCentralizedBinding binding;

    private FragPagerAdapter pagerAdapter;
    private ArrayList<Fragment> mFragments;
    private String[] titles;

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerHomeComponent.builder().appComponent(appComponent).homeModule(new HomeModule(this)).build().inject(this);
    }

    /**
     * @param context
     * @param type    集采类型groupBuyType 1 即报集采  2 汇总集采 3 企业专项
     */
    public static void start(Context context, String type) {
        Intent intent = new Intent();
        intent.putExtra("type", type);
        intent.setClass(context, CentralizedActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(CentralizedActivity.this, R.layout.activity_centralized);
        binding.include.ivBack.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }

    @Override
    protected void init() {
        viewModel.getFirstCategory(getIntent().getStringExtra("type"));
    }

    @Override
    protected void initView() {

    }

    public void showFirstCategory(List<PickSelectEntity> datas) {
        if (datas == null || datas.size() == 0) {
            return;
        }
        mFragments = new ArrayList<>();
        int size = datas.size();
        titles = new String[size];
        for (int i = 0; i < size; i++) {
          //  mFragments.add(CentralizedMiningFragment3.newInstance(i,datas.get(i).getNo(), getIntent().getStringExtra("type")));
            titles[i] = datas.get(i).getProjectscale();
        }
        pagerAdapter = new FragPagerAdapter(getSupportFragmentManager(), mFragments);

        binding.viewpager.setAdapter(pagerAdapter);
        binding.viewpager.setOffscreenPageLimit(titles.length - 1);
        binding.tablayout.setViewPager(binding.viewpager, titles);
    }
}
